package com.fzy.common.entity;

import java.util.HashMap;
import java.util.Map;

/**
 * response返回数据
 */
public class ResultBean extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResultBean() {
        put("code", 0);
        put("msg", "success");
    }

    public static ResultBean error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static ResultBean error(String msg) {
        return error(500, msg);
    }

    public static ResultBean error(int code, String msg) {
        ResultBean resultBean = new ResultBean();
        resultBean.put("code", code);
        resultBean.put("msg", msg);
        return resultBean;
    }

    public static ResultBean ok(String msg) {
        ResultBean resultBean = new ResultBean();
        resultBean.put("msg", msg);
        return resultBean;
    }

    public static ResultBean ok(Map<String, Object> map) {
        ResultBean resultBean = new ResultBean();
        resultBean.putAll(map);
        return resultBean;
    }

    public static ResultBean ok() {
        return new ResultBean();
    }

    @Override
    public ResultBean put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}